#include "setcoordinate2dialog.h"
#include "ui_setcoordinate2dialog.h"
#include "hmicommondefine.h"
#include "instructionEnum.h"
#include <QMessageBox>
#include "coordinatehelpdialog.h"

SetCoordinate2Dialog::SetCoordinate2Dialog(int styleIdIn,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SetCoordinate2Dialog)
{
    ui->setupUi(this);
    styleId=styleIdIn;
    helpDialog=NULL;
    move(0,0);
    initialDisplayStyle(styleId);
//#ifdef BUILD_ARM
//    setGeometry(70,128,460,595);
//#endif

    strHead << tr("J1") << tr("J2") << tr("J3") << tr("J4") << tr("J5") << tr("J6");
    ui->position_tableWidget->setHorizontalHeaderLabels(strHead);

//    ui->position_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->position_tableWidget->setColumnCount(D_ROBOT_AXIS_MAX);

    ui->position_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选择模式，选择单行
    ui->position_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

    //INIT
    setInputEnable(false);
    ui->radioThreePoint->setChecked(true);

    tmpThreeTool.pointList.resize(3);
    tmpThreeTool.method = ENUM_TOOL_3POINTS;

    tmpSixTool.pointList.resize(6);
    tmpSixTool.method = ENUM_TOOL_6POINTS;

    tmpInputTool.xyzwpr.resize(6);//由于tmpThreeTool tmpSixTool公共此xyz数据
    tmpInputTool.method = ENUM_TOOL_XYZWPR;

    tmpTwentyPointToolInfo.pointList.resize(20);
    tmpTwentyPointToolInfo.method = ENUM_TOOL_20POINTS;

    tmpTwentyPointZeroToolInfo.pointList.resize(20);
    tmpTwentyPointZeroToolInfo.method = ENUM_TOOL_20POINTS_ZEROCAL;

    tmpTwentyThreePointToolInfo.pointList.resize(23);
    tmpTwentyThreePointToolInfo.method = ENUM_TOOL_23POINTS;

    tmpThreeUser.pointList.resize(3);
    tmpThreeUser.method = ENUM_USER_3POINTS;

    tmpFourUser.pointList.resize(4);
    tmpFourUser.method = ENUM_USER_4POINTS;

    tmpInputUser.xyzwpr.resize(6);//tmpThreeUser tmpFourUser公共此xyz数据
    tmpInputUser.method = ENUM_USER_XYZWPR;
}

void SetCoordinate2Dialog::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        this->setGeometry(0,0,600,450);
        ui->position_tableWidget->setGeometry(15,160,580,230);

        ui->recordPoint_Btn->setGeometry(20,400,80,40);
        ui->moveToPoint_Btn->setGeometry(150,400,80,40);
        ui->calculate_Btn->setGeometry(250,400,80,40);
        ui->buttonHelp->setGeometry(350,400,80,40);
        ui->forward_Btn->setGeometry(500,400,80,40);

        break;
    default:
        break;
    }
}
SetCoordinate2Dialog::~SetCoordinate2Dialog()
{
    delete ui;
}

void SetCoordinate2Dialog::updateResult()
{
    //工具坐标系
    if(0 == currentShowCoordinate)
    {

        //massInfo
        ui->frame_massInfo->show();
        ui->lineEdit_toolMass->setText(QString::number(tmpInputTool.mass,'f',2));
        if(0==tmpInputTool.massCenter.size())
        {
            ui->lineEdit_toolMass_x->setText("空");
            ui->lineEdit_toolMass_y->setText("空");
            ui->lineEdit_toolMass_z->setText("空");

        }
        else
        {
            ui->lineEdit_toolMass_x->setText(QString::number(tmpInputTool.massCenter[0],'f',2));
            ui->lineEdit_toolMass_y->setText(QString::number(tmpInputTool.massCenter[1],'f',2));
            ui->lineEdit_toolMass_z->setText(QString::number(tmpInputTool.massCenter[2],'f',2));
        }


        ui->label_coordinateType->setText("工具坐标系");
        //init 示教类型
        ui->radiosixOrFourPoint->setText(tr("6点法"));
        ui->radio_methodext1->show();
        ui->radio_methodext2->show();
        ui->radio_methodext3->show();
        ui->error_label->show();
        ui->error_lineEdit->show();

        //init X Y Z W P R 数据
        QString data = QString::number(tmpInputTool.xyzwpr[0],'f',2);
        ui->X_lineEdit->setText(data);
        data = QString::number(tmpInputTool.xyzwpr[1],'f',2);
        ui->Y_lineEdit->setText(data);
        data = QString::number(tmpInputTool.xyzwpr[2],'f',2);
        ui->Z_lineEdit->setText(data);
        data = QString::number(tmpInputTool.xyzwpr[3],'f',2);
        ui->W_lineEdit->setText(data);
        data = QString::number(tmpInputTool.xyzwpr[4],'f',2);
        ui->P_lineEdit->setText(data);
        data = QString::number(tmpInputTool.xyzwpr[5],'f',2);
        ui->R_lineEdit->setText(data);
        data = QString::number(tmpInputTool.error,'f',2);
        ui->error_lineEdit->setText(data);
        ui->lineEdit_name->setText(QString::fromStdString(tmpInputTool.name));

        //init 点数据
        ui->position_tableWidget->setHorizontalHeaderLabels(strHead);//设置头部

        if(ENUM_TOOL_3POINTS == tmpInputTool.method)
        {
            ui->radioThreePoint->setChecked(true);//三点
            beforeRadioCheck = ENUM_TOOL_3POINTS;
            setInputEnable(false);//禁止输入

            int rowCount = tmpThreeTool.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }


                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpThreeTool.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpThreeTool.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }


        }
        else if(ENUM_TOOL_6POINTS == tmpInputTool.method)
        {
            ui->radiosixOrFourPoint->setChecked(true);
            beforeRadioCheck = ENUM_TOOL_6POINTS;
            setInputEnable(false);

            int rowCount = tmpSixTool.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }


                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpSixTool.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpSixTool.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }


        }
        else if(ENUM_TOOL_20POINTS == tmpInputTool.method)
        {
            ui->radio_methodext1->setChecked(true);
            beforeRadioCheck = ENUM_TOOL_20POINTS;
            setInputEnable(false);

            int rowCount = tmpTwentyPointToolInfo.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }


                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpTwentyPointToolInfo.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpTwentyPointToolInfo.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }


        }
        else if(ENUM_TOOL_20POINTS_ZEROCAL == tmpInputTool.method)
        {
            ui->radio_methodext3->setChecked(true);
            beforeRadioCheck = ENUM_TOOL_20POINTS_ZEROCAL;
            setInputEnable(false);

            int rowCount = tmpTwentyPointZeroToolInfo.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }


                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpTwentyPointZeroToolInfo.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpTwentyPointZeroToolInfo.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }


        }
        else if(ENUM_TOOL_23POINTS == tmpInputTool.method)
        {
            ui->radio_methodext2->setChecked(true);
            beforeRadioCheck = ENUM_TOOL_23POINTS;
            setInputEnable(false);

            int rowCount = tmpTwentyThreePointToolInfo.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }


                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpTwentyThreePointToolInfo.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpTwentyThreePointToolInfo.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }


        }
        else if(ENUM_TOOL_XYZWPR == tmpInputTool.method)
        {
            beforeRadioCheck = ENUM_TOOL_XYZWPR;
            ui->radioInput->setChecked(true);
            setInputEnable(true);

            ui->position_tableWidget->clear();
            ui->position_tableWidget->setRowCount(0);
        }
        else//有些数据是没有任何示教信息的
        {
            ui->radioThreePoint->setChecked(false);
            ui->radiosixOrFourPoint->setChecked(false);
            ui->radioInput->setChecked(false);

            ui->position_tableWidget->setItem(0,0,new QTableWidgetItem(""));
        }


    }
    //用户坐标系
    else if(1 == currentShowCoordinate)
    {
        ui->frame_massInfo->hide();
         ui->label_coordinateType->setText("用户坐标系");
        //init 类型
        ui->radiosixOrFourPoint->setText(tr("4点法"));
        ui->radio_methodext1->hide();
        ui->radio_methodext2->hide();
        ui->radio_methodext3->hide();
        ui->error_label->hide();
        ui->error_lineEdit->hide();

        //init xyz wpr 数据
        QString data = QString::number(tmpInputUser.xyzwpr[0],'f',2);
        ui->X_lineEdit->setText(data);
        data = QString::number(tmpInputUser.xyzwpr[1],'f',2);
        ui->Y_lineEdit->setText(data);
        data = QString::number(tmpInputUser.xyzwpr[2],'f',2);
        ui->Z_lineEdit->setText(data);
        data = QString::number(tmpInputUser.xyzwpr[3],'f',2);
        ui->W_lineEdit->setText(data);
        data = QString::number(tmpInputUser.xyzwpr[4],'f',2);
        ui->P_lineEdit->setText(data);
        data = QString::number(tmpInputUser.xyzwpr[5],'f',2);
        ui->R_lineEdit->setText(data);
        ui->error_lineEdit->clear();
        ui->lineEdit_name->setText(QString::fromStdString(tmpInputUser.name));

        //init 点数据
        ui->position_tableWidget->setHorizontalHeaderLabels(strHead);
        if(ENUM_USER_3POINTS == tmpInputUser.method)
        {
            beforeRadioCheck = ENUM_USER_3POINTS;
            ui->radioThreePoint->setChecked(true);
            setInputEnable(false);

            int rowCount = tmpThreeUser.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }

//            if(rowCount != ui->position_tableWidget->rowCount())
            {
                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpThreeUser.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpThreeUser.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }
            }
//            else
//            {
//                for(int i = 0; i < rowCount; i ++)
//                {
//                    for(int j = 0; j < 6; j ++)
//                    {
//                        if(j < tmpThreeUser.pointList[i].positionValue.size() )
//                        {
//                            QString data = QString("%1").arg(tmpThreeUser.pointList[i].positionValue[j]);
//                            ui->position_tableWidget->item(i, j)->setText(data);
//                        }
//                        else
//                        {
//                            ui->position_tableWidget->item(i, j)->setText("-");
//                        }
//                    }
//                }
//            }

        }
        else if(ENUM_USER_4POINTS == tmpInputUser.method)
        {
            beforeRadioCheck = ENUM_USER_4POINTS;
            ui->radiosixOrFourPoint->setChecked(true);
            setInputEnable(false);

            int rowCount = tmpFourUser.pointList.size();
            ui->position_tableWidget->setRowCount(rowCount);

            QStringList hStrList;
            for(int i = 0; i < rowCount; i++)
            {
                hStrList << tr("P")+QString::number(i+1);
                ui->position_tableWidget->setVerticalHeaderLabels(hStrList);
            }

//            if(rowCount != ui->position_tableWidget->rowCount())
            {
                for(int i = 0; i < rowCount; i ++)
                {
                    for(int j = 0; j < 6; j ++)
                    {
                        if(j < tmpFourUser.pointList[i].positionValue.size() )
                        {
                            QString data = QString::number(tmpFourUser.pointList[i].positionValue[j],'f',2);
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(data));
                        }
                        else
                        {
                            ui->position_tableWidget->setItem(i, j, new QTableWidgetItem(""));
                        }
                    }
                }
            }
//            else
//            {
//                for(int i = 0; i < rowCount; i ++)
//                {
//                    for(int j = 0; j < 6; j ++)
//                    {
//                        if(j < tmpFourUser.pointList[i].positionValue.size() )
//                        {
//                            QString data = QString("%1").arg(tmpFourUser.pointList[i].positionValue[j]);
//                            ui->position_tableWidget->item(i, j)->setText(data);
//                        }
//                        else
//                        {
//                            ui->position_tableWidget->item(i, j)->setText("-");
//                        }
//                    }
//                }
//            }
        }
        else if(ENUM_USER_XYZWPR == tmpInputUser.method)
        {
            beforeRadioCheck = ENUM_USER_XYZWPR;
            ui->radioInput->setChecked(true);
            setInputEnable(true);

            ui->position_tableWidget->clear();
            ui->position_tableWidget->setRowCount(0);
        }
        else//有些数据是没有任何示教信息的(仍有点问题)
        {
            ui->radioThreePoint->setChecked(false);
            ui->radiosixOrFourPoint->setChecked(false);
            ui->radioInput->setChecked(false);

            ui->position_tableWidget->setItem(0,0,new QTableWidgetItem(""));
        }
    }
    //? ui->position_tableWidget->selectRow(pointIndex);
}

void SetCoordinate2Dialog::on_forward_Btn_clicked()
{
    this->hide();
}

/**
 * @brief EditCoordinate::updateView　更新设置数据到控件上
 */
void SetCoordinate2Dialog::updateView(int currentShowCoordinate,int currentCoordinateIndex)
{
    this->currentShowCoordinate = currentShowCoordinate;
    this->currentCoordinateIndex = currentCoordinateIndex;

    updateResult();

}

void SetCoordinate2Dialog::updateError(double errorResult)
{
    ui->error_lineEdit->setText(QString::number(errorResult,'g',3));
}

void SetCoordinate2Dialog::on_recordPoint_Btn_clicked()
{
//    int coordinateIndex = setCoordinateView->currentCoordinateIndex;
    pointIndex = ui->position_tableWidget->currentRow();

    if(0 == currentShowCoordinate)
    {
        if(ENUM_TOOL_XYZWPR!=tmpInputTool.method)
        {
            emit recordPoint(currentShowCoordinate,tmpInputTool.method, pointIndex);
        }
        else
        {
            qDebug()<<"tmpInputTool.method wrong = "<<tmpInputTool.method;
        }
    }
    else if(1 == currentShowCoordinate)
    {
        if(ENUM_USER_XYZWPR!=tmpInputUser.method)
        {
            emit recordPoint(currentShowCoordinate,tmpInputUser.method, pointIndex);
        }
        else
        {
            qDebug()<<"tmpInputUser.method wrong = "<<tmpInputUser.method;
        }
    }
}

void SetCoordinate2Dialog::on_calculate_Btn_clicked()
{
    //将所有数据集中再tmpInput
    //因为,只有tmpInput有index和method

    bool flag = false;

    if(currentShowCoordinate == 0)
    {
        tmpInputTool.name=ui->lineEdit_name->text().toStdString();
        if(ui->radio_methodext1->isChecked())
        {
            //20点
            tmpInputTool.pointList.resize(20);
            if(20 == tmpTwentyPointToolInfo.pointList.size())
            {
                for(int i = 0;i<20;i++)
                {
                    tmpInputTool.pointList[i] = tmpTwentyPointToolInfo.pointList[i];
                }
                flag = true;
            }


        }
        if(ui->radio_methodext3->isChecked())
        {
            //20点zero
            tmpInputTool.pointList.resize(20);
            if(20 == tmpTwentyPointZeroToolInfo.pointList.size())
            {
                for(int i = 0;i<20;i++)
                {
                    tmpInputTool.pointList[i] = tmpTwentyPointZeroToolInfo.pointList[i];
                }
                flag = true;
            }


        }
        if(ui->radio_methodext2->isChecked())
        {
            //23点
            tmpInputTool.pointList.resize(23);
            if(23 == tmpTwentyThreePointToolInfo.pointList.size())
            {
                for(int i = 0;i<23;i++)
                {
                    tmpInputTool.pointList[i] = tmpTwentyThreePointToolInfo.pointList[i];
                }
                flag = true;
            }
        }
        if(ui->radioThreePoint->isChecked())
        {
            //三点
            tmpInputTool.pointList.resize(3);
            if(3 == tmpThreeTool.pointList.size())
            {
                for(int i = 0;i<3;i++)
                {
                    tmpInputTool.pointList[i] = tmpThreeTool.pointList[i];
                }
                flag = true;
            }
        }
        if(ui->radiosixOrFourPoint->isChecked())
        {
            //六点
            tmpInputTool.pointList.resize(6);
            if(6 == tmpSixTool.pointList.size())
            {
                for(int i = 0;i<6;i++)
                {
                    tmpInputTool.pointList[i] = tmpSixTool.pointList[i];
                }
                flag = true;
            }
        }
        if(ui->radioInput->isChecked())
        {
            //直接
            if(6 != tmpInputTool.xyzwpr.size())
            {
                tmpInputTool.xyzwpr.resize(6);
            }

            tmpInputTool.xyzwpr[0] = ui->X_lineEdit->text().toFloat();
            tmpInputTool.xyzwpr[1] = ui->Y_lineEdit->text().toFloat();
            tmpInputTool.xyzwpr[2] = ui->Z_lineEdit->text().toFloat();
            tmpInputTool.xyzwpr[3] = ui->W_lineEdit->text().toFloat();
            tmpInputTool.xyzwpr[4] = ui->P_lineEdit->text().toFloat();
            tmpInputTool.xyzwpr[5] = ui->R_lineEdit->text().toFloat();

            flag = true;
        }

    }
    else
    {
        tmpInputUser.name=ui->lineEdit_name->text().toStdString();
        if(ui->radioThreePoint->isChecked())
        {
            //三点
            tmpInputUser.pointList.resize(3);//input

            if(3 == tmpThreeUser.pointList.size())
            {
                for(int i = 0;i<3;i++)
                {
                    tmpInputUser.pointList[i] = tmpThreeUser.pointList[i];
                }
                flag = true;
            }
        }
        if(ui->radiosixOrFourPoint->isChecked())
        {
            //四点
            tmpInputUser.pointList.resize(4);//input

            if(4 == tmpFourUser.pointList.size())
            {
                for(int i = 0;i<4;i++)
                {
                    tmpInputUser.pointList[i] = tmpFourUser.pointList[i];
                }
                flag = true;
            }
        }
        if(ui->radioInput->isChecked())
        {
            //直接
            if(6 != tmpInputUser.xyzwpr.size())
            {
                tmpInputUser.xyzwpr.resize(6);
            }

            tmpInputUser.xyzwpr[0] = ui->X_lineEdit->text().toFloat();
            tmpInputUser.xyzwpr[1] = ui->Y_lineEdit->text().toFloat();
            tmpInputUser.xyzwpr[2] = ui->Z_lineEdit->text().toFloat();
            tmpInputUser.xyzwpr[3] = ui->W_lineEdit->text().toFloat();
            tmpInputUser.xyzwpr[4] = ui->P_lineEdit->text().toFloat();
            tmpInputUser.xyzwpr[5] = ui->R_lineEdit->text().toFloat();

            flag = true;
        }
    }

    clearResultView();

    if(flag)
    {
        emit calculateCoordinate(currentShowCoordinate, currentCoordinateIndex);
    }
    else
    {
        qDebug()<<"calulate flag false";
    }
}

//void SetCoordinate2Dialog::on_forward_Btn_clicked()
//{
//    setCoordinateView->viewFlag = 0;

//    this->close();
//    setCoordinateView->show();

//}

void SetCoordinate2Dialog::on_moveToPoint_Btn_pressed()
{
//    int coordinateType = setCoordinateView->currentShowCoordinate;
//    int coordinateIndex = setCoordinateView->currentCoordinateIndex;
    MoveParameter sendPoint;
    sendPoint.pointType = 0;    //普通点
    sendPoint.moveType = 0;     //默认关节方式移动
    sendPoint.targetPoint.jointFlag = 0;

    pointIndex = ui->position_tableWidget->currentRow();
    if(pointIndex<0)
    {
        qDebug()<<"no point - point index is -1";
        return;
    }

    if(0 == currentShowCoordinate)
    {
        if(ui->radioThreePoint->isChecked())
        {
            if(pointIndex<3)
            {
                //if(tmpThreeTool.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpThreeTool.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpThreeTool.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpThreeTool.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpThreeTool.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }
            }
        }
        else if(ui->radiosixOrFourPoint->isChecked())
        {
            if(pointIndex<6)
            {
                //if(tmpSixTool.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpSixTool.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpSixTool.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpSixTool.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpSixTool.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }

            }
        }
        else if(ui->radio_methodext1->isChecked())
        {
            if(pointIndex<20)
            {
                //if(tmpSixTool.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpTwentyPointToolInfo.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpTwentyPointToolInfo.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpTwentyPointToolInfo.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpTwentyPointToolInfo.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }

            }
        }
        else if(ui->radio_methodext3->isChecked())
        {
            if(pointIndex<20)
            {
                //if(tmpSixTool.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpTwentyPointZeroToolInfo.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpTwentyPointZeroToolInfo.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpTwentyPointZeroToolInfo.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpTwentyPointZeroToolInfo.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }

            }
        }
        else if(ui->radio_methodext2->isChecked())
        {
            if(pointIndex<23)
            {
                //if(tmpSixTool.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpTwentyThreePointToolInfo.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpTwentyThreePointToolInfo.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpTwentyThreePointToolInfo.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpTwentyThreePointToolInfo.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }

            }
        }

        else{}
    }
    else
    {
        if(ui->radioThreePoint->isChecked())
        {
            if(pointIndex<3)
            {
                //if(tmpThreeUser.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpThreeUser.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpThreeUser.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpThreeUser.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpThreeUser.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }
            }
        }
        else if(ui->radiosixOrFourPoint->isChecked())
        {
            if(pointIndex<4)
            {
                //if(tmpFourUser.pointList[pointIndex].recordStatus)
                {
                    for(int i = 0;i < tmpFourUser.pointList[pointIndex].positionValue.size();i++)
                    {
                        sendPoint.targetPoint.positionValue.push_back(tmpFourUser.pointList[pointIndex].positionValue[i]);//float
                    }
                    for(int i = 0;i < tmpFourUser.pointList[pointIndex].extPositionValue.size();i++)
                    {
                        sendPoint.targetPoint.extPositionValue.push_back(tmpFourUser.pointList[pointIndex].extPositionValue[i]);//float
                    }

                    emit moveToCoordinatePointPress(sendPoint);
                }
                //else
                {
                    //qDebug()<<"no teach this point!";
                }
            }
        }
        else{}
    }

}

void SetCoordinate2Dialog::on_moveToPoint_Btn_released()
{
//    int coordinateType = setCoordinateView->currentShowCoordinate;
//    int coordinateIndex = setCoordinateView->currentCoordinateIndex;
//    pointIndex = ui->position_tableWidget->currentRow();

    emit moveToCoordinatePointRelease();
}


void SetCoordinate2Dialog::on_radioThreePoint_clicked()
{
    if(beforeRadioCheck == ENUM_TOOL_3POINTS)
    {
        return;
    }
    beforeRadioCheck = ENUM_TOOL_3POINTS;//==ENUM_USER_3POINTS
    //设置表格
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_3POINTS;

        //从6 转移 3点
        for(int i = 0;i<3;i++)
        {
            tmpThreeTool.pointList[i] = tmpSixTool.pointList[i];
        }

    }
    else
    {
        tmpInputUser.method = ENUM_USER_3POINTS;

        //从4 转移 3点
        for(int i = 0;i<3;i++)
        {
            tmpThreeUser.pointList[i] = tmpFourUser.pointList[i];
        }
    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radiosixOrFourPoint->setChecked(false);
    ui->radioInput->setChecked(false);

    setInputEnable(false);
}

void SetCoordinate2Dialog::on_radiosixOrFourPoint_clicked()
{    
    if(beforeRadioCheck == ENUM_TOOL_6POINTS)
    {
        return;//如果同一个,返回,不操作
    }
    beforeRadioCheck = ENUM_TOOL_6POINTS;//=ENUM_USER_4POINTS
    //设置表格
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_6POINTS;

        //从3 转移 6点
        for(int i = 0;i<3;i++)
        {
            tmpSixTool.pointList[i] = tmpThreeTool.pointList[i];
        }
    }
    else
    {
        tmpInputUser.method = ENUM_USER_4POINTS;

        //从3 转移 4点
        for(int i = 0;i<3;i++)
        {
            tmpFourUser.pointList[i] = tmpThreeUser.pointList[i];
        }
    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radioThreePoint->setChecked(false);
    ui->radioInput->setChecked(false);

    setInputEnable(false);
}

void SetCoordinate2Dialog::on_radioInput_clicked()
{
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_XYZWPR;

        if(beforeRadioCheck == ENUM_TOOL_3POINTS)
        {
            //从3 转移 6点
            for(int i = 0;i<3;i++)
            {
                tmpSixTool.pointList[i] = tmpThreeTool.pointList[i];
            }
        }
        if(beforeRadioCheck == ENUM_TOOL_6POINTS)
        {
            //从6 转移 3点
            for(int i = 0;i<3;i++)
            {
                tmpThreeTool.pointList[i] = tmpSixTool.pointList[i];
            }
        }
    }
    else
    {
        tmpInputUser.method = ENUM_USER_XYZWPR;

        if(beforeRadioCheck == ENUM_USER_3POINTS)
        {
            //从3 转移 4点
            for(int i = 0;i<3;i++)
            {
                tmpFourUser.pointList[i] = tmpThreeUser.pointList[i];
            }
        }
        if(beforeRadioCheck == ENUM_USER_4POINTS)
        {
            //从4 转移 3点
            for(int i = 0;i<3;i++)
            {
                tmpThreeUser.pointList[i] = tmpFourUser.pointList[i];
            }
        }
    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radioThreePoint->setChecked(false);
    ui->radioInput->setChecked(false);

    //设置可输入
    setInputEnable(true);
}

void SetCoordinate2Dialog::setInputEnable(bool value)
{
    ui->X_lineEdit->setEnabled(value);
    ui->Y_lineEdit->setEnabled(value);
    ui->Z_lineEdit->setEnabled(value);
    ui->W_lineEdit->setEnabled(value);
    ui->P_lineEdit->setEnabled(value);
    ui->R_lineEdit->setEnabled(value);

    if(value)
    {
        ui->moveToPoint_Btn->setEnabled(false);
        ui->recordPoint_Btn->setEnabled(false);
    }
    else
    {
        ui->moveToPoint_Btn->setEnabled(true);
        ui->recordPoint_Btn->setEnabled(true);
    }
}

void SetCoordinate2Dialog::changeLanguage()
{
    ui->retranslateUi(this);
}

void SetCoordinate2Dialog::on_button_setToolMass_clicked()
{
    double mass=ui->lineEdit_toolMass->text().toDouble();
    QVector<double> center;
    center.append(ui->lineEdit_toolMass_x->text().toDouble());
    center.append(ui->lineEdit_toolMass_y->text().toDouble());
    center.append(ui->lineEdit_toolMass_z->text().toDouble());
    emit setToolMass_signal(currentCoordinateIndex,mass,center);
}

void SetCoordinate2Dialog::on_radio_methodext1_clicked(bool checked)
{
    if(beforeRadioCheck == ENUM_TOOL_20POINTS)
    {
        return;//如果同一个,返回,不操作
    }
    beforeRadioCheck = ENUM_TOOL_20POINTS;//=ENUM_USER_4POINTS
    //设置表格
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_20POINTS;


    }
    else
    {

    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radioThreePoint->setChecked(false);
    ui->radioInput->setChecked(false);

    setInputEnable(false);
}

void SetCoordinate2Dialog::on_buttonHelp_clicked()
{
    if(NULL==helpDialog)
    {
        helpDialog=new CoordinateHelpDialog(styleId,this);
    }
    helpDialog->show();

}

void SetCoordinate2Dialog::on_radio_methodext2_clicked(bool checked)
{
    if(beforeRadioCheck == ENUM_TOOL_23POINTS)
    {
        return;//如果同一个,返回,不操作
    }
    beforeRadioCheck = ENUM_TOOL_23POINTS;//=ENUM_USER_4POINTS
    //设置表格
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_23POINTS;


    }
    else
    {

    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radioThreePoint->setChecked(false);
    ui->radioInput->setChecked(false);

    setInputEnable(false);
}

void SetCoordinate2Dialog::clearResultView()
{
    //init X Y Z W P R 数据
    ui->X_lineEdit->setText("");
    ui->Y_lineEdit->setText("");
    ui->Z_lineEdit->setText("");
    ui->W_lineEdit->setText("");
    ui->P_lineEdit->setText("");
    ui->R_lineEdit->setText("");
    ui->error_lineEdit->setText("");
}

void SetCoordinate2Dialog::on_radio_methodext3_clicked()
{
    if(beforeRadioCheck == ENUM_TOOL_20POINTS_ZEROCAL)
    {
        return;//如果同一个,返回,不操作
    }
    beforeRadioCheck = ENUM_TOOL_20POINTS_ZEROCAL;//=ENUM_USER_4POINTS
    //设置表格
    if(currentShowCoordinate == 0)
    {
        tmpInputTool.method = ENUM_TOOL_20POINTS_ZEROCAL;


    }
    else
    {

    }
    updateView(currentShowCoordinate,currentCoordinateIndex);//重新刷新界面

    //
    ui->radioThreePoint->setChecked(false);
    ui->radioInput->setChecked(false);

    setInputEnable(false);
}
